/**
	Pulsar engine. Core.
	Additional include file. Commnand line processing.

	Copyright (C) 2013-2014 Dmitry Dolgov

	This program is free software; you can redistribute it and/or modify it under the terms of the
	GNU General Public License as published by the Free Software Foundation; either version 2 of
	the License, or (at your option) any later version.
		
	This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
	without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
	See the GNU General Public License for more details.
*/

namespace pl
{

/**
	Command line processing
*/
class CommandLine
{
public:
	/// Default ctor
	explicit CommandLine() : 
	_nArgs(0), 
	_ppArgList(NULL) ,
	_errorFlag(false)
	{
	}

	/// WinMain()-style ctor
	explicit CommandLine(const wchar_t* cmdLine, int firstArg = 0);
	explicit CommandLine(const char* cmdLine, int firstArg = 0);

	/// main()-style ctor
	explicit CommandLine(int argc, const wchar_t* argv[], int firstArg = 1);
	explicit CommandLine(int argc, const char* argv[], int firstArg = 1);

	/// Dtor
	~CommandLine();

	/// Get count if arguments
	inline pl_uint32 count() const
	{
		return _nArgs; 
	}

	/// Get argument by index (0, 1, ... count()-1)
	const pl_char* getArg(pl_uint32 index) const;

	/// Get argument by index (0, 1, ... count()-1)
	inline const pl_char* operator [](pl_uint32 index) const
	{
		return getArg(index); 
	}

	/// Find argument in list
	pl_uint32 findArg(const pl_char* arg, bool fCaseSensitive) const;

	/// Find argument in list followed by argument
	const pl_char* findArg1(const pl_char* arg, bool fCaseSensitive) const;

	/// Check errors while constructed
	inline bool isError() const
	{
		return _errorFlag;
	}

private:
	/// Amount or arguments
	pl_uint32 _nArgs;
	/// List of arguments
	pl_char** _ppArgList;

	/// Split to args
	pl_uint32 _splitArgs(const pl_char* cmdLine, pl_char** destArray, int firstArg);
	/// Extract arg
	pl_char* _extractArg(const pl_char* p1, const pl_char* p2);
	/// Error while parsing
	bool _errorFlag;
};

} // namespace pl 

//
// End of file 'pulsar_cmdline.h'
//
